Add PUT /users/:id (update a user) - #92
Open
adi1651adi1651 wants to merge 3 commits into
Open
Conversation
Mirrors getUserById's not-found signal (returns undefined) so routes can branch on it the same way they already do for GET /users/:id.
Follows the existing patterns in this file: POST's validation (missing name/email -> 400) and GET /:id's not-found handling (missing user -> 404). Turns tests/update-user.test.js green.
Explains the approved plan, model choice, commit split, and what the self-review checked before opening the PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
store.updateUser(id, { name, email })— reusesgetUserById, returnsundefinedfor an unknown id so the route can branch on it the same wayGET /:idalready does.PUT /users/:idinroutes/users.js:400whennameoremailis missing (same validation asPOST /),404when the id doesn't exist,200with the updated user otherwise.NOTES.mdwith the plan, model choice, commit split, and self-review notes.No changes to
server.jsor any test file —tests/update-user.test.jswas already written and is now green.Test plan
npm test— 9/9 passing, including all threeupdate-user.test.jscases (update, 404, 400) and thenotes.test.jschecks.npm run lint— clean.:id(Number("x")isNaN, never matches a real id, so it 404s instead of crashing), empty-stringname/email(still falsy, still 400s), and confirmedexpress.json()is already wired up forPUTthe same asPOST.A reviewer should specifically try: updating a real user (200 + updated fields),
PUT /users/9999(404), and aPUTwith onlynameor onlyemail(400).